package smartcampus.scjava.controller.third;

import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import smartcampus.scjava.POJO.DO.Xuesheng;
import smartcampus.scjava.config.Result;
import org.springframework.web.bind.annotation.*;
import smartcampus.scjava.service.StartTalkService;
import smartcampus.scjava.service.XueshengService;

import javax.annotation.Resource;

@RestController
@RequestMapping("/xuesheng")
public class XueshengController {

    @Resource
    private XueshengService xueshengService;
    @Autowired
    private StartTalkService startTalkService;


    /**
     * 分页条件查询
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/selectPage")
    public Result selectPage(@RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "2") Integer pageSize,
                             Xuesheng xuesheng){
        PageInfo<Xuesheng> pageInfo = xueshengService.selectPage(pageNum, pageSize,xuesheng);
        return Result.success(pageInfo);
    }

    @GetMapping("/totalPage")
    public Result totalPage(){
        int total = xueshengService.totalPage();
        int totalPage;
        if (total%5==0){
            totalPage = total/5;
        }else {
            totalPage = total/5 + 1;
        }
        return Result.success(totalPage);
    }

    /**
     * 新增毕业生信息
     * @param xuesheng
     * @return
     */
    @PostMapping("/add")
    public Result add(@RequestBody Xuesheng xuesheng){
        xueshengService.add(xuesheng);
        return Result.success();
    }

    /**
     * 更新毕业生信息
     * @param xuesheng
     * @return
     */
    @PutMapping("/update")
    public Result update(@RequestBody Xuesheng xuesheng){
        xueshengService.updateById(xuesheng);
        return Result.success();
    }

    /**
     * 删除毕业生信息
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id){
        xueshengService.deleteById(id);
        return Result.success();
    }

    /**
     * 语音识别
     */
    @RequestMapping("/start_talk")
    public void startTalk(){
        startTalkService.startTalk();
    }
}
